package small.common.loadBalance;

import small.common.core.collection.CollectionUtil;

import java.util.List;

public abstract class AbstractLoadBalance<T extends BalanceNode,V extends BalanceInvoker> implements LoadBalance<T,V>{

    @Override
    public T select(List<T> nodes,V invoker) {
        if (CollectionUtil.isEmpty(nodes)) {
            return null;
        }
        if (nodes.size() == 1) {
            return nodes.get(0);
        }
        return doSelect(nodes,invoker);
    }

    protected abstract T  doSelect(List<T> balances,V invoker);

}
